package br.uvv.Model;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="ti_cenario_base")
public class CenarioBase extends EntidadeGenerica {

	private static final long serialVersionUID = 4995354265001186764L;

	@Column(length=127)
	private String nome;
	
	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	@JoinColumn(name="cliente_id")
	private ClientePortal cliente;

	//E OS ARGUMENTOS?
	
	@OneToMany(mappedBy="cenarioBase", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	private List<FluxoBase> fluxosBase;
	
	@Override
	public String toJson() {
		return null;
	}
	
	public String getNome() {
		return nome;
	}
	
	public void setNome(String nome) {
		this.nome = nome;
	}

	public ClientePortal getCliente() {
		return cliente;
	}
	
	public void setCliente(ClientePortal cliente) {
		this.cliente = cliente;
	}
	
	public List<FluxoBase> getFluxosBase() {
		return fluxosBase;
	}
	
	public void setFluxosBase(List<FluxoBase> fluxosBase) {
		this.fluxosBase = fluxosBase;
	}
	
	public String getFluxoList(){
		if (fluxosBase == null)
			return "Sem Fluxos Cadastrados";
		String tmp = "";
		int aux = 0;
		int i = 0;
		for (FluxoBase b:fluxosBase){
			aux = b.getCodFluxo().split("[/.]").length;
			while (i<aux){
				tmp += " ";
				i++;
			}
			tmp+=b.getCodFluxo();
			tmp+= " - " + b.getAcao() + "<br/>";
		}
		return tmp;
	}
}
